package Tests;

import static org.junit.Assert.*;

import java.security.InvalidKeyException;
import java.security.spec.InvalidKeySpecException;

import org.junit.Before;
import org.junit.Test;

import Email.auto.checker.Account;
import Email.auto.checker.Comunication;
import Email.auto.checker.DESEncryption;
import Email.auto.checker.Tray;

public class testAccount {

	private Tray tray;
	private Comunication comunication;
	private DESEncryption des;  

	@Before
	public void setUp(){
		comunication = new Comunication();
		try {
			des = new DESEncryption("umachave");
		} catch (InvalidKeyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidKeySpecException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		tray = new Tray(comunication, null,des);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testAccount() throws IllegalArgumentException{
		Account acc = new Account(null,null);
	}
	
	@Test
	public void testGetDomain() {
		Account acc = new Account(tray,comunication);
		assertEquals("gmail.com", acc.getDomainFromEmail("coisas@gmail.com"));
		assertEquals("gmail.com", acc.getDomainFromEmail("coisas.coisas@gmail.com"));
		
		assertEquals("isec.pt", acc.getDomainFromEmail("coisas@isec.pt"));
		assertEquals("isec.pt", acc.getDomainFromEmail("coisas.outrascoisas@isec.pt"));
		
	}

}
